<?php
namespace Apps\BoxEng\Model;

use Think\Model;

class EngSubtitleWordsModel extends \BaseModel
{

    public function get_page($start_time, $minute = 10)
    {
        $page = ceil(intval((strtotime($start_time) - strtotime("00:00:00")) / 60) / $minute); //10分钟一页
        if ($page == 0) {
            $page = 1;
        }
        return $page;
    }

    public function load_words($id)
    {
        $key = "load_words_" . $id;
        $data = S($key);
        if ($data) {
            return $data;
        }
        $data = $this->get("subtitle_id='$id'", "", "id");
        $list = array();
        foreach ($data as $k => $one) {
            if (!$one['part_id']) {
                $page = $this->get_page($one['start_time']);
            } else {
                $page = $one['part_id'];
            }
            $list[$page][] = $one;
        }
        foreach ($list as $k => $data) {
            $start_time = $list[$k][0]['start_time'];
            if (strtotime($start_time) - strtotime("00:00:00") > 4) {
                $start_time = strtotime($start_time) - 5;
            }
            foreach ($data as $k2 => $one) {
                $end_time_arr = explode(".", $one['end_time']);
                $start_time_arr = explode(".", $one['start_time']);
                $start_time_end = $start_time_arr[1] ? $start_time_arr[1] : "000";
                $end_time_end = $end_time_arr[1] ? $end_time_arr[1] : "000";
                $one['start_time_int'] = trim((strtotime($one['start_time']) - $start_time) . "." . $start_time_end);
                $one['end_time_int'] = trim((strtotime($one['end_time']) - $start_time) . "." . $end_time_end);
                $eng = explode(" ", $one['english']);
                foreach ($eng as $k3 => $word) {
                    $eng[$k3] = "<a  tabindex='0' data-toggle='popover'   class='eng_word'>" . $word . "</a>";
                }
                $one['show_english'] = implode(" ", $eng);
                $data[$k2] = $one;
            }

            $list[$k] = $data;
        }
        S($key, $list);
        $this->set_cache("select", $key);
        return $list;
    }

}
 